/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SiteSelectionPanel.java
 *
 * Created on 2009-10-06, 10:19:01
 */

package pl.tom.social.analyzer.gui.panel;

import java.util.ArrayList;
import java.util.List;
import pl.tom.social.dal.SocialDatabaseFacade;

/**
 *
 * @author Tom
 */
public class SiteSelectionPanel extends javax.swing.JPanel {

    /** Creates new form SiteSelectionPanel */
    public SiteSelectionPanel() {
        initComponents();

		SocialDatabaseFacade db = new SocialDatabaseFacade();
		List<String> sites = db.getAllSitesUrls();
		siteSelectionList.setListData(sites.toArray());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        siteSelectionScrollPane = new javax.swing.JScrollPane();
        siteSelectionList = new javax.swing.JList();

        setLayout(new java.awt.BorderLayout());

        siteSelectionScrollPane.setViewportView(siteSelectionList);

        add(siteSelectionScrollPane, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JList siteSelectionList;
    private javax.swing.JScrollPane siteSelectionScrollPane;
    // End of variables declaration//GEN-END:variables

	public List<String> getSelected() {
		List<String> result = new ArrayList<String>();
		Object[] objs = siteSelectionList.getSelectedValues();
		for(Object obj:objs) {
			if(obj instanceof String) {
				result.add((String)obj);
			}
		}
		return result;
	}
}
